#coding=utf-8
import os

RES_EXT = [".png", ".jpg"]
RES_ROOT = "./res"
QRC_NAME = "./res/resource.qrc"
PY_NAME = "Resource.py"

def ScanPath(root, iList):
	if not root:
		return
	for item in os.listdir(root):
		full = os.path.join(root, item)
		if os.path.isdir(full):
			ScanPath(full, iList)
		elif os.path.isfile(full):
			name, ext = os.path.splitext(item)
			ext = ext.lower()
			if not ext in RES_EXT:
				continue
			iList.append([name, item])

def CreateQRC():
	iList = []
	ScanPath(RES_ROOT, iList)

	f = open(QRC_NAME, "w")
	txt = '<!DOCTYPE RCC>\n<RCC version="1.0">\n\t<qresource>\n'
	for name,item in iList:
		txt += '\t\t<file alias="%s">%s</file>\n' % (name, item)
	txt += '\t</qresource>\n</RCC>'
	f.write(txt)
	f.close()
			
CreateQRC()
cmd = "pyrcc4 -o %s %s" % (PY_NAME, QRC_NAME)
os.system(cmd)
